package o;

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import o.emm.b;
import o.emm.e;

public class emq implements b {
    private static Comparator<emf> ॱ = new Comparator<emf>() {
        public /* synthetic */ int compare(Object obj, Object obj2) {
            return ॱ((emf) obj, (emf) obj2);
        }

        public int ॱ(emf o_emf, emf o_emf2) {
            if (o_emf == null || o_emf2 == null) {
                return 0;
            }
            if ("CN".equals(ContentManager.getInstant().getContext().getResources().getConfiguration().locale.getCountry())) {
                return edf.ˋ().ॱ(eqp.ˊ(o_emf.ˋ())).compareTo(edf.ˋ().ॱ(eqp.ˊ(o_emf2.ˋ())));
            }
            return eqp.ˊ(o_emf.ˋ()).compareTo(eqp.ˊ(o_emf2.ˋ()));
        }
    };
    private List<emf> ˊ = new ArrayList();
    private e ˏ;

    public emq(e eVar) {
        this.ˏ = eVar;
    }

    public void ˎ(List<emf> list) {
        if (!list.isEmpty()) {
            Collections.sort(list, ॱ);
            ॱ(list);
            this.ˏ.ॱ(this.ˊ);
        }
    }

    private void ॱ(List<emf> list) {
        this.ˊ.clear();
        for (int i = 0; i < list.size(); i++) {
            emf o_emf = (emf) list.get(i);
            o_emf.ॱ(1);
            if (this.ˊ.size() <= 0) {
                ˋ(o_emf);
                if (!this.ˊ.contains(o_emf)) {
                    this.ˊ.add(o_emf);
                }
            } else {
                ˊ(o_emf);
                if (!this.ˊ.contains(o_emf)) {
                    this.ˊ.add(o_emf);
                }
            }
        }
    }

    private void ˊ(emf o_emf) {
        Object ˊ = ((emf) this.ˊ.get(this.ˊ.size() - 1)).ˊ();
        if (!TextUtils.isEmpty(ˊ)) {
            Object ˊ2 = o_emf.ˊ();
            if (!TextUtils.isEmpty(ˊ2) && !ˊ2.startsWith(ˊ)) {
                emf o_emf2 = new emf();
                o_emf2.ॱ(2);
                this.ˊ.add(o_emf2);
                o_emf2 = new emf();
                o_emf2.ॱ(0);
                o_emf2.ॱ(o_emf.ˊ());
                this.ˊ.add(o_emf2);
            }
        }
    }

    private void ˋ(emf o_emf) {
        if (!TextUtils.isEmpty(o_emf.ˊ())) {
            emf o_emf2 = new emf();
            o_emf2.ॱ(0);
            o_emf2.ॱ(o_emf.ˊ());
            this.ˊ.add(o_emf2);
        }
    }

    public void ˋ(String str) {
        int i = 0;
        while (this.ˊ != null && i < this.ˊ.size()) {
            emf o_emf = (emf) this.ˊ.get(i);
            if (o_emf == null || TextUtils.isEmpty(o_emf.ˊ()) || !o_emf.ˊ().equalsIgnoreCase(str)) {
                i++;
            } else {
                this.ˏ.ˎ(i);
                return;
            }
        }
    }
}
